package com.yulan.bankback.converter;

import com.yulan.bankback.entity.model.admin.AbnormalUser;
import com.yulan.bankback.entity.model.admin.KindUser;
import com.yulan.bankback.entity.model.admin.ViolationUser;
import com.yulan.bankback.entity.model.bank.BankUser;
import com.yulan.bankback.entity.vo.UserVo;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class UserConverter {

    private static String strDateFormat = "yyyy-MM-dd HH:mm:ss";

    private static SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);

    public void converterUser2UserVo(BankUser user, UserVo userVo){
        userVo.setAccount(user.getAccount());
        userVo.setHeadImgUrl(user.getHeadImgUrl());
        userVo.setMoney(user.getMoney());
        userVo.setUserName(user.getUserName());
        userVo.setLastLoginTime(sdf.format(user.getLastLoginTime()));
        userVo.setNotFreeMoney(user.getNotFreeMoney());
        userVo.setSafeScore(user.getSafeScore());
        userVo.setUserType(user.getUserType());
        userVo.setUid(user.getId());
    }


    public AbnormalUser convertUserToAbnormal(BankUser user, String type, String ip){
        AbnormalUser abnormalUser = new AbnormalUser();
        abnormalUser.setUid(user.getId());
        abnormalUser.setCreateTime(new Date());
        abnormalUser.setType(type);
        abnormalUser.setIp(ip);
        abnormalUser.setUsername(user.getUserName());
        return abnormalUser;
    }

    public KindUser convertUser2KindUser(BankUser user, String type, String blackOrWhite){
        KindUser kindUser = new KindUser();
        kindUser.setUid(user.getId());
        kindUser.setCreateTime(new Date());
        kindUser.setUsername(user.getUserName());
        kindUser.setType(type);
        kindUser.setBlackOrWhite(blackOrWhite);
        return kindUser;
    }

    public ViolationUser convertUser2Violation(BankUser user, String violationType, String city){
        ViolationUser violationUser = new ViolationUser();
        violationUser.setUid(user.getId());
        violationUser.setBornDate(user.getBornDate());
        violationUser.setViolationType(violationType);
        violationUser.setViolationTime(new Date());
        violationUser.setUsername(user.getUserName());
        violationUser.setCity(city);
        return violationUser;
    }

}
